package com.zxy.dao;

import com.zxy.utils.DBCPUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ZhihuDao {

    public List<Map<String, Object>> followingQuestions() {
        QueryRunner queryRunner = new QueryRunner(DBCPUtil.getDataSource());
        List<Map<String, Object>> mapList = new ArrayList<>();
        try {
            mapList = queryRunner.query("select title,url from zhihu_following_questions order by id desc ", new MapListHandler());

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return mapList;
    }

    public List<Map<String, Object>> collection() {
        QueryRunner queryRunner = new QueryRunner(DBCPUtil.getDataSource());
        List<Map<String, Object>> mapList = new ArrayList<>();
        try {
            mapList = queryRunner.query("select title,url from zhihu_collection order by id desc ", new MapListHandler());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return mapList;
    }

    public List<Map<String, Object>> hignValueProgrammer() {
        QueryRunner queryRunner = new QueryRunner(DBCPUtil.getDataSource());
        List<Map<String, Object>> mapList = new ArrayList<>();
        try {
            mapList = queryRunner.query("select author_url,img_urls from `zhihu_当一个颜值很高的程序员是怎样一番体验？`", new MapListHandler());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return mapList;
    }

}
